package oa.hleast.xswl.controller.app.appsicon;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.result.Result;
import oa.hleast.xswl.pojo.vo.appsicon.HomePageAppsIconVo;
import oa.hleast.xswl.service.ISysCommonConfigService;
import oa.hleast.xswl.service.ISysDictItemService;
import oa.hleast.xswl.service.ISysDictService;
import oa.hleast.xswl.service.IUmsUserService;
import oa.hleast.xswl.service.appsicon.IAppsIconService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 302
 * @description
 * @date 2021/3/17
 */
@Api(tags = "【移动端】应用图标管理")
@RestController
@RequestMapping("/api.app/v1/appsIcon")
@AllArgsConstructor
@Slf4j
public class AppsIconController {

    private final IAppsIconService appsIconService;
    private final IUmsUserService umsUserService;
    private final ISysDictService dictService;
    private final ISysCommonConfigService commonConfigService;
    private final ISysDictItemService dictItemService;

    @ApiOperation(value = "首页应用图标", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, paramType = "query", dataType = "Long",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "limit", value = "每页数量", required = true, paramType = "query", dataType = "Long",dataTypeClass = Long.class),
            @ApiImplicitParam(name = "configKey", value = "配置项key", required = true, paramType = "query", dataType = "Long",dataTypeClass = Long.class)
    })
    @GetMapping("getHomePageIcon")
    public Result<List<HomePageAppsIconVo>> getHomePageIcon(@RequestParam @NonNull Integer page,
                                                            @RequestParam @NonNull Integer limit,
                                                            @RequestParam @NotBlank String configKey) {
        // TODO 后面这里看看怎么改
        log.info("configKey = {}",configKey);
        Long dictItemAppsIconTypeId = dictItemService.getDictItemByConfigKey(configKey).getId();


        Page<HomePageAppsIconVo> result = appsIconService.getHomePageIcon(page, limit, dictItemAppsIconTypeId);
        return Result.success(result.getRecords(), result.getTotal());
    }


}
